<?php //$Id: class.PhoneNumber.php,v 1.1.1.1 2014/08/23 06:57:06 ymlam Exp $ Copyright (C) 2014 Link2Tek LLC ?>
<?php

class PhoneNumber
{
        public static function formatE164($phone)
        {
                $reg = "[,()\+\-]";
                // remove blanks
                $phone = str_replace(" ", "", $phone);
                // check if already E.164, indicated by a leading '+'
                $pos = strpos($phone, '+');
                if ($pos !== false && $pos == 0)
                {
                        // remove '+' and punctuations and return
                        return ereg_replace($reg, "", $phone);
                }
                // remove other punctuations
                $phone = ereg_replace($reg, "", $phone);

                // check if US 10-digit phone number
                if (strlen($phone) == 10)
                {
                        // US 10-digit number.  Add country code '1'.
                         return '1' . $phone;
                }
                return $phone;

        }
}

?>
